package ch.bfh.mobicomp.soda2.barometer;

import android.app.Service;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.IBinder;
import android.util.Log;

public class BarometerService extends Service  {

	private Sensor baroSensor;
	private SensorManager baroSensorManager;
	private BarometerListener baroListener;
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		baroSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
		baroSensor = baroSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
		baroListener = new BarometerListener(this);
		
		baroSensorManager.registerListener(baroListener, baroSensor, SensorManager.SENSOR_DELAY_NORMAL);
		
		Log.d(MainActivity.LOG_TAG, "Service onCreate");
		
	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		
		Log.d(MainActivity.LOG_TAG, "Serice onStartCommand");
		
		return super.onStartCommand(intent, flags, startId);
	}
	
	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		
		Log.d(MainActivity.LOG_TAG, "Service onDestroy");
	}
	
	@Override
	public void onLowMemory() {
		// TODO Auto-generated method stub
		super.onLowMemory();
		
		baroSensorManager.unregisterListener(baroListener);
		
		Log.d(MainActivity.LOG_TAG, "Service onLowMemory");		
	}

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

}
